home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / presto / presto10.lha / src / synchro.C < prev    next >
C/C++ Source or Header  |  1991-12-11  |  1KB  |  63 lines

  1. /*
  2.  * synchro.c
  3.  *    Definitions for base synchro class SynchroObject,
  4.  *    and non inlineable code for the derived synchro classes
  5.  *    (locks and monitors)
  6.  *
  7.  *    Last modified:        1/2/88
  8.  *    by:            bnb
  9.  *    reason:            Remove necessary for named objects
  10.  *
  11.  *    Last modified:        12/21/87
  12.  *    by:            bnb
  13.  *    reason:            add these comments
  14.  *
  15.  */
  16.  
  17.  
  18. #define _SYNCHRO_C
  19.  
  20. #include "presto.h"
  21.  
  22.  
  23.  
  24. //
  25. // Can not be defined in-line cuz it needs to know about ThreadQ's
  26. //
  27.  
  28. SynchroObject::SynchroObject(int t, char *name)    : Object(t,name)
  29. {
  30.     so_waiting = new ThreadQUnlocked(TS_BLOCKED);
  31.     so_lock = new Spinlock;
  32. }
  33.  
  34.  
  35. SynchroObject::~SynchroObject()
  36. {
  37.     Thread *t;
  38.     lock();
  39.     if (so_waiting->empty())    {
  40.         delete so_waiting;
  41.     }
  42.     else    {
  43.         cerr << "ERROR:" << thisproc << "\nUnsatisfied synchro object [" <<
  44.              this->name() << "]\n";
  45.         while (t = so_waiting->get())    {
  46.             t->print(cerr);
  47.             cerr << "\n";
  48.         }
  49.         error("Cannot delete synchronization object");
  50.         delete so_waiting;
  51.     }
  52.     unlock();
  53.     delete so_lock;
  54. }
  55.  
  56.  
  57. void
  58. SynchroObject::print(ostream &s)
  59. {
  60.     s << form("(SynchroObject)this=0x%x", this) << name() <<
  61.          "so_lock=" << so_lock << " so_waiting= " << so_waiting;
  62. }
  63.